package com.akilesa.dictcreator;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by IntelliJ IDEA.
 * User: akilesa
 * Date: 21.01.2010
 * Time: 11:49:00
 * To change this template use File | Settings | File Templates.
 */
public class AnkiCardsCreator {

    OnlineDictionary dict=new OnlineDictionary();

    public List<AnkiCard> create(EnglishWordTokenizerResult tokens){

        long notFounded=0;
        List<AnkiCard> result=new ArrayList<AnkiCard>();
        for(EnglishWordTokenizerResult.WordDescription item: tokens.getWords()){
            System.out.print("\u001B[0J");
            System.out.print("Processing of word "+item.getWord());
            System.out.print("\u001B[1G");
            AnkiCard card=new AnkiCard();
            card.setQuestion(item.getWord());
            String answer=dict.translate(item.getWord());
            if(answer!=null && !"".equals(answer)){
                card.setAnswer(answer);
                result.add(card);
            }else{
                notFounded++;
            }
        }
        Statistic.getInstance().setWordNotFoundCount(notFounded);
        Statistic.getInstance().setCardTotalCount(result.size());
        return result;
    }
}

